import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { NavController } from '@ionic/angular';

@Component({
  selector: 'app-cinema',
  templateUrl: './cinema.page.html',
  styleUrls: ['./cinema.page.scss'],
})
export class CinemaPage implements OnInit {
  city: any;
  geoloc = window.navigator.geolocation;
  pois: any;
  constructor(public http: HttpClient, public nav: NavController) {}

  ngOnInit() {
    this.geoloc.getCurrentPosition(
      (msg) => {
        console.log(msg);
        // 逆地理编码
        // //restapi.amap.com/v3/geocode/regeo?key=6b5c25e5e62b0a6f011f0c5d64aabb98&location=${this.long},${this.lat}
        // 周边搜索
        // //restapi.amap.com/v3/place/around?key=6b5c25e5e62b0a6f011f0c5d64aabb98&location=${this.long},${this.lat}&keywords=影院&offset=20&page=1&extensions=all
        const url = `//restapi.amap.com/v3/place/around?key=6b5c25e5e62b0a6f011f0c5d64aabb98&location=${msg.coords.latitude},${msg.coords.longitude}&keywords=影院&offset=20&page=1&extensions=all`;
        this.http.get(url).subscribe((res: any) => {
          console.log(res);
          this.pois = res.pois;
          // this.city = res.regeocode.addressComponent.city.slice(0, -1);
        });
      },
      (err) => console.log('err:' + err),
      { timeout: 5000 }
    );
  }
  segmentChanged(e) {
    console.log(e.detail.value);
    this.nav.navigateForward('/tabs/tab2');
  }
}
